<template>
  <div id="imagesList" v-loading="dataLoading">
    <div
      class="item"
      v-for="(item, index) in themeList"
      :key="index"
      @click="itemClick(item)"
    >
      <div :class="item.resourcesSrc">
        <i class="el-icon-star-off musicCurrent"></i>
      </div>
      <div>{{ item.resourcesName }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "musicList",
  props: ["activate"],
  data() {
    return {
      loaded: false, // 是否已激活
      dataLoading: false,
      themeList: [],
    };
  },
  watch: {
    activate: {
      handler: "activateChange",
      deep: true,
    },
  },
  created() {
    this.activateChange();
  },
  mounted() {},
  methods: {
    /**
     * 监听现在激活的tab
     **/
    activateChange() {
      if (this.activate && !this.loaded) {
        // 如果未加载过，现在开始加载
        this.loaded = true;
        this.getData(); // 获取资源列表
      }
    },
    /**
     * 获取资源列表
     * @param
     */
    async getData() {
      // 走接口取数据
      this.themeList = [
        { resourcesName: "无背景音乐", resourcesType: 7, resourcesSrc: "" },
        { resourcesName: "音乐1", resourcesType: 7, resourcesSrc: "1" },
        { resourcesName: "音乐2", resourcesType: 7, resourcesSrc: "2" },
      ];
    },
    /**
     * 项目点击返回该项信息
     * @param item
     */
    itemClick(item) {
      this.$emit("selectedMusic", item); // 向父级传递参数
    },
  },
};
</script>

<style lang='scss' scoped>
#imagesList {
  width: 100%;
  height: 100%;
  position: relative;
  overflow-y: auto;
  .item {
    width: 100%;
    text-align: center;
    margin-bottom: 0px;
    cursor: pointer;
    div:first-child {
      width: 100px;
      height: 100px;
      border-radius: 5px;
      -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      margin: 10px auto;
    }
    i {
      display: block;
      font-size: 70px;
      line-height: 100px;
    }
  }
  .item:hover {
    div:first-child {
      -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.3);
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.3);
    }
    font-size: 17px;
    i {
      display: block;
      font-size: 80px;
    }
  }
}
#imagesList::-webkit-scrollbar-track-piece {
  // 滚动条凹槽的颜色，还可以设置边框属性
  background-color: #f8f8f8;
}
#imagesList::-webkit-scrollbar {
  // 滚动条的宽度
  width: 6px;
  height: 6px;
}
#imagesList::-webkit-scrollbar-thumb {
  // 滚动条的设置
  background-color: #dddddd;
  background-clip: padding-box;
  min-height: 28px;
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
}
#imagesList::-webkit-scrollbar-thumb:hover {
  background-color: #bbb;
}
.musicCurrent {
  -webkit-transform: rotate(360deg);
  animation: rotation 3s linear infinite;
  -moz-animation: rotation 3s linear infinite;
  -webkit-animation: rotation 3s linear infinite;
  -o-animation: rotation 3s linear infinite;
}
@-webkit-keyframes rotation {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
  }
}
@-moz-keyframes rotation {
  from {
    -moz-transform: rotate(0deg);
  }
  to {
    -moz-transform: rotate(360deg);
  }
}
@-o-keyframes rotation {
  from {
    o: rotate(0deg);
  }
  to {
    o: rotate(360deg);
  }
}
@keyframes rotation {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>
